VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsLevels"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Type typeL
 d(1 To 5, 1 To 30) As Byte '8*5=40
End Type

Private lvs() As typeL
Private lvc As Long

Private clv As Long

Public Property Get Count() As Long
Count = lvc
End Property

Public Property Get CurrentLevel() As Long
CurrentLevel = clv
End Property

Public Property Let CurrentLevel(ByVal n As Long) '
clv = n
End Property

Public Sub ReadLevel(Optional ByVal lv As Long)
Dim i As Long, j As Long, k As Long
Dim a As Long, b As Long
If lv = 0 Then lv = clv
If lv > 0 And lv <= lvc Then
 For i = 1 To 5
  For j = 1 To 30
   b = lvs(lv).d(i, j)
   a = 1
   For k = 1 To 8
    LevelData(i * 8 + k - 8, j) = Sgn(a And b)
    a = a + a
   Next k
  Next j
 Next i
End If
End Sub

Public Sub WriteLevel(Optional ByVal lv As Long)
Dim i As Long, j As Long, k As Long
Dim a As Long, b As Long
If lv = 0 Then lv = clv
If lv > 0 And lv <= lvc Then
 For i = 1 To 5
  For j = 1 To 30
   b = 0
   a = 1
   For k = 1 To 8
    If LevelData(i * 8 + k - 8, j) = 1 Then b = b Or a
    a = a + a
   Next k
   lvs(lv).d(i, j) = b
  Next j
 Next i
End If
End Sub

Public Sub InsertLevel(Optional ByVal lv As Long)
If lv = 0 Then lv = clv
If lv > 0 And lv <= lvc Then
 lvc = lvc + 1
 ReDim Preserve lvs(1 To lvc)
 CopyMemory lvs(lv + 1), lvs(lv), (lvc - lv) * 150&
 Erase lvs(lv).d
End If
End Sub

Public Sub DeleteLevel()
If lvc = 1 Then
 Erase lvs(1).d
Else
 If lvc = clv Then
  clv = clv - 1
 Else
  CopyMemory lvs(clv), lvs(clv + 1), (lvc - clv) * 150&
 End If
 lvc = lvc - 1
 ReDim Preserve lvs(1 To lvc)
End If
End Sub

Public Sub MoveBackward()
Dim tmp As typeL
If lvc > 1 And clv > 1 Then
 tmp = lvs(clv)
 lvs(clv) = lvs(clv - 1)
 clv = clv - 1
 lvs(clv) = tmp
End If
End Sub

Public Sub MoveForward()
Dim tmp As typeL
If lvc > 1 And clv < lvc Then
 tmp = lvs(clv)
 lvs(clv) = lvs(clv + 1)
 clv = clv + 1
 lvs(clv) = tmp
End If
End Sub

Public Sub LoadFile(ByVal FileName As String)
On Error GoTo a
Open FileName For Binary As #1
Get #1, 1, lvc
If lvc <= 0 Then lvc = 1
ReDim lvs(1 To lvc)
Get #1, 5, lvs
a:
Close
End Sub

Public Sub SaveFile(ByVal FileName As String)
On Error GoTo a
Open FileName For Output As #1
Close
Open FileName For Binary As #1
Put #1, 1, lvc
Put #1, 5, lvs
a:
Close
End Sub

Private Sub Class_Initialize()
Clear
End Sub

Public Sub Clear()
lvc = 1
ReDim lvs(1 To 1)
clv = 1
End Sub
